/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AIproccess;

import Army.building.Building;
import Army.BuildingAndUnit;
import Army.ComputerTeam;
import GameObject.LayerManager;
import java.awt.Point;

/**
 *
 * @author Huy
 */
public class PlayerAIDevelope extends PlayerAI {

	public PlayerAIDevelope(LayerManager layer, ComputerTeam team) {
		super(layer, team);
	}

	protected Building getCastle(ComputerTeam team) {
		for (int i = 0; i < team.getListBuilding().size(); i++) {
			Building building = team.getListBuilding().get(i);
			if (building.getType() == BuildingAndUnit.Type.BuildingCastle) {
				return building;
			}
		}
		return null;
	}

	protected Building getBarrack(ComputerTeam team) {
		for (int i = team.getListBuilding().size() - 1; i >= 0; i--) {
			Building building = team.getListBuilding().get(i);
			if (building.getType() == BuildingAndUnit.Type.BuildingBarrack && building.isCompleted()) {
				return building;
			}
		}
		return null;
	}

	protected Point getPosition(ComputerTeam team, int r) {
		int i = (int) (Math.random() * team.getListBuilding().size());
		if (i == team.getListBuilding().size()) {
			return new Point(0, 0);
		}
		Building base = team.getListBuilding().get(i);
		return getPosition(base, r);

	}

	protected Point getPosition(BuildingAndUnit base, int r) {
		int dx = RANDOM.nextInt(r) + base.getSize();
		if (RANDOM.nextFloat() > 0.5) {
			dx = -dx;
		}
		int dy = RANDOM.nextInt(r) + base.getSize();
		if (RANDOM.nextFloat() > 0.5) {
			dy = -dy;
		}
		if (RANDOM.nextFloat() > 0.4) {
			if (RANDOM.nextFloat() > 0.5) {
				dx -= base.getSize();
			} else {
				dy -= base.getSize();
			}
		}

		return new Point(base.getPosition().x + dx, base.getPosition().y + dy);
	}
	
}
